<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/headeradmin.php");
?>
<section>
    <script>
    function reload(form){
    var val=form.kamer.options[form.kamer.options.selectedIndex].value;
    self.location='kameronderdelen.php?kamer=' + val ;
    }
    </script>
<hgroup>
<h1>Kamer-onderdelen</h1>
</hgroup>
    <input type="button" value="Terug naar kamers" onclick="javascript:history.back();" /><br><br>
    <form name="kamerform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
        <select onchange="reload(this.form)" name="kamer">
            <option value="0">Kies een kamer</option>
            <?php
            $sql = "SELECT * from roomtype";
            $result = mysql_query($sql) or die (mysql_error());
            while($rij = mysql_fetch_array($result))
            {
                if (isset($_GET['kamer']))
                {
                    if ($_GET['kamer'] == $rij['Id'])
                    {
                        echo "<option selected value=\"".$rij['Id']."\">".$rij['Name']."</option>";
                    }
                    else
                    {
                        echo "<option value=\"".$rij['Id']."\">".$rij['Name']."</option>";
                    }
                }
                else
                {
                    echo "<option value=\"".$rij['Id']."\">".$rij['Name']."</option>";
                }
            }
            ?>
    </select>
    </form>
    
    
<?php
if (isset($_GET['kamer']))
{
    echo "Klik <a href=\"kameronderdeeltoevoegen.php?kamer=".$_GET['kamer']."\">hier</a> om een nieuw kamer-onderdeel toe te voegen.<br><br>";
$page_name="kameronderdelen.php?kamer=".$_GET['kamer']."";
if (isset($_GET['start']))
{
    $start=$_GET['start'];
}
else
{
    $start=0;
}

if(strlen($start) > 0 and !is_numeric($start)){
	exit;
}
$eu = ($start - 0);
$limit = 20; // No of records to be shown per page.
$thi = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
$query2="SELECT * from roomitem where RoomId=".$_GET['kamer']."";
$result2=mysql_query($query2);
$nume=mysql_num_rows($result2);
?>

<table id="rounded-corner">
    <thead>
    	<tr>
        	<th scope="col" class="rounded-company">Onderdeel-ID</th>
                <th scope="col" class="rounded-q1">Kamer</th>
            <th scope="col" class="rounded-q1">Onderdeel</th>
            <th scope="col" class="rounded-q2">Status</th>
            <th scope="col" class="rounded-q3">Problemen</th>
            <th scope="col" class="rounded-q4">Bewerken</th>
        </tr>
    </thead>
        <tfoot>
    	<tr>
        	<td colspan="5" class="rounded-foot-left">
        	<?php
	        	if ( $limit < $nume) {
	        		if($back >=0) {
						echo "<a href='$page_name&start=$back'>Vorige</a>";
					}
	        		$i=0;
					$l=1;
					for($i=0;$i < $nume;$i=$i+$limit){
						if($i <> $eu)
						{
							echo " <a href='$page_name&start=$i'>$l</a> ";
						}
						else 
						{ 
							echo "<span style=\"font-weight:bold;\">$l</span>";
						}
						$l=$l+1;
					}
	        		if($thi < $nume) 
	        		{
						echo "<a href='$page_name&start=$next'>Volgende</a>";
					}
				}
        	?>
        	</td>
        	<td class="rounded-foot-right">&nbsp;</td>
        </tr>
    </tfoot>
    <tbody>
<?php

$sql1 = "SELECT * from roomitem where RoomId=".$_GET['kamer']." limit $eu, $limit";
$result1 = mysql_query($sql1) or die (mysql_error());
while($row = mysql_fetch_array($result1))
{
    echo "<tr><td>".$row['Id']."</td>";
    
    $sql2 = "SELECT Name from roomtype where Id=".$row['RoomId']."";
    $result2 = mysql_query($sql2) or die (mysql_error());
    while($rij = mysql_fetch_array($result2))
    {
        echo "<td>" . $rij['Name']."</td>";
    }
    echo "<td>" . $row['Name']."</td>";
if ($row['Activated'] == "T")
{
    $activated = "Geactiveerd";
}
else
{
    $activated = "Gedeactiveerd";
}
echo "<td>" . $activated."</td>";
echo "<td><a href=\"onderdeelprobleem.php?onderdeel=".$row['Id']."&kamer=".$_GET['kamer']."\" >Bekijk onderdeel-problemen</a></td>";
echo "<td><a href=\"kameronderdeelaanpassen.php?id=".$row['Id']."&kamer=".$_GET['kamer']."\" >Bewerken</a></td>";


}
}
?>
</tbody>
</table>


</section>

<?php
    include($_SERVER['DOCUMENT_ROOT']."/ObstacleWebApp/view/footer.php");
?>
